package com.sgb.kjwl.view.ui.adapter.machine;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemAskLeaseWebsiteBinding;
import com.sgb.kjwl.model.entity.lease.AskLeaseSheBeiEntity;
import com.sgb.kjwl.model.entity.lease.AskLeaseWebsiteEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

/**
 * 企业网站-租赁需求列表适配器
 */
public class AskLeaseWebsiteAdapter extends BaseRecycleAdapter<AskLeaseWebsiteEntity> {

    public AskLeaseWebsiteAdapter(Context context, List<AskLeaseWebsiteEntity> datas) {
        super(context, R.layout.item_ask_lease_website, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, AskLeaseWebsiteEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemAskLeaseWebsiteBinding binding = (ItemAskLeaseWebsiteBinding) holder.getmBinding();
        //状态(1:报价中;3:报价结束;4:已完成)
        if (entity.getStatus() == 1) {
            binding.ivQuoteState.setImageResource(R.mipmap.price_ing);
        } else if (entity.getStatus() == 3) {
            binding.ivQuoteState.setImageResource(R.mipmap.price_end_gray);
        } else if (entity.getStatus() == 4) {
            binding.ivQuoteState.setImageResource(R.mipmap.price_finish_fail);
        }

        try {
            //设置租赁时长
            if (TextUtils.isEmpty(entity.getRentalDuration()) || Double.parseDouble(entity.getRentalDuration()) <= 0) {
                binding.tvLeaseTime.setText("面议");
            } else {
                binding.tvLeaseTime.setText(entity.getRentalDuration() + entity.getRentalDurationUnit());
            }
            //租赁价格
            if (TextUtils.isEmpty(entity.getPrice())) {
                binding.tvPrice.setText("面议");
            } else {
                binding.tvPrice.setText(entity.getPrice());
            }
            if (TextUtils.isEmpty(entity.getNumOrArea())) {
                binding.tvNum.setText("面议");
            } else {
                binding.tvNum.setText(entity.getNumOrArea());
            }
            //发布时间
            binding.tvLeasePublicTime.setText(DateUtils.stampToDay(entity.getUpdateTime()));
        } catch (Exception ex) {
        }

        //设置房产,土地,工厂租赁面积名称
        if ("4".equals(entity.getType()) || "5".equals(entity.getType()) || "6".equals(entity.getType())) {//土地求租
            binding.tvNumLabel.setText("租赁面积：");
        } else {
            binding.tvNumLabel.setText("租赁数量：");
        }

    }
}
